﻿using System;
using System.Collections.Generic;
using YJKTextTool;

namespace YJKTextDimension.Utility
{
	public class SpecialCharactorAnalyser
	{
		public static List<SpecialCharactorAnalyser.CharactorInfo> SplitString(string text)
		{
			List<int> list = new List<int>();
			for (int i = 0; i < text.Length; i++)
			{
				string a = WindowsCharacterSet.StringToUnicode(text, i);
				if (a == "AC00" || a == "AC01" || a == "AC02" || a == "AC03")
				{
					list.Add(i);
				}
			}
			List<SpecialCharactorAnalyser.CharactorInfo> list2 = new List<SpecialCharactorAnalyser.CharactorInfo>();
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				int num2 = list[i] - num;
				string text2 = text.Substring(0, num2);
				if (text2.CompareTo("") != 0)
				{
					list2.Add(new SpecialCharactorAnalyser.CharactorInfo
					{
						m_Type = SpecialCharactorAnalyser.CharactorType.GeneralCharactor,
						m_Text = text2
					});
					num += text2.Length;
				}
				string text3 = text.Substring(num2, 1);
				list2.Add(new SpecialCharactorAnalyser.CharactorInfo
				{
					m_Type = SpecialCharactorAnalyser.CharactorType.SpecialCharactor,
					m_Text = text3
				});
				num++;
				text = text.Substring(num2 + 1, text.Length - num2 - 1);
			}
			if (text.CompareTo("") != 0)
			{
				list2.Add(new SpecialCharactorAnalyser.CharactorInfo
				{
					m_Type = SpecialCharactorAnalyser.CharactorType.GeneralCharactor,
					m_Text = text
				});
			}
			for (int i = 0; i < list2.Count - 1; i++)
			{
				SpecialCharactorAnalyser.CharactorInfo value = list2[i];
				if (value.m_Type == list2[i + 1].m_Type)
				{
					value.m_Text += list2[i + 1].m_Text;
					list2[i] = value;
					list2.RemoveAt(i + 1);
					i--;
				}
			}
			return list2;
		}

		public enum CharactorType
		{
			GeneralCharactor,
			SpecialCharactor
		}

		public struct CharactorInfo
		{
			public SpecialCharactorAnalyser.CharactorType m_Type;

			public string m_Text;
		}
	}
}
